#ifndef EREMOTETCPSOCKET_H
#define EREMOTETCPSOCKET_H

#include "eremoteprotocol_global.h"
#include <QTcpSocket>

class EREMOTEPROTOCOLSHARED_EXPORT RemoteTcpSocket : public QTcpSocket
{
    Q_OBJECT
public:
    explicit RemoteTcpSocket(QObject *parent = nullptr);
    virtual ~RemoteTcpSocket() override;
    bool mustWrite(const char *data, qint64 len);
    inline bool mustWrite(const QByteArray &data)
    { return mustWrite(data.constData(), data.size()); }

    static QByteArray getVersion();
    bool sendVersion();
    bool sendPacket(const QByteArray &pkt);
signals:
    void receivedVersion(const QByteArray&);

protected slots:
    void ReadData();

protected:
    virtual void parsePacket(QByteArray &pkt);

private:
    bool m_readyReadVersion;
    bool m_readyReadSize;
    int m_packetSize;
    int m_readPacketSize;
    QByteArray m_packet;
};

#endif // EREMOTETCPSOCKET_H
